var SysCategoryTool = function(option) {
	var me = this;
	me.levelone = option.levelone;
	me.leveltwo = option.leveltwo;
	me.levelthree = option.levelthree;
	me.onedefault = option.onedefault;
	$("#" + me.levelone).change(function() {
		me._selectLevelOne();
	});
	$("#" + me.leveltwo).change(function() {
		me._selectLevelTwo();
	});
	me._init();
};
SysCategoryTool.prototype = {
	_init : function() {
		var me = this;
		var levelThreeId = $("#" + me.levelthree+"_value").val();
		$.getJSON("syscategory_init?data=" + new Date() + "&systemCategoryUtil.levelThreeId="
				+ levelThreeId, function(data) {
			me._refreshLevelOne(data);
			me._refreshLevelTwo(data);
			me._refreshLevelThree(data);
		})
	},
	_selectLevelOne : function() {
		var me = this;
		var levelOneId = $("#" + me.levelone).val();
		$.getJSON("syscategory_selectLevelOne?data=" + new Date()
				+ "&systemCategoryUtil.levelOneId=" + levelOneId,
				function(data) {
					me._refreshLevelTwo(data);
					me._refreshLevelThree(data);
				})
	},
	_selectLevelTwo : function() {
		var me = this;
		var levelTwoId = $("#" + me.leveltwo).val();
		$.getJSON("syscategory_selectLevelTwo?data=" + new Date()
				+ "&systemCategoryUtil.levelTwoId=" + levelTwoId,
				function(data) {
					me._refreshLevelThree(data);
				})
	},
	_refreshLevelOne : function(data) {
		var me = this;
		$("#" + me.levelone).empty();
		var line = "";
		if(me.onedefault == "ok"){
			line = "<option value='0'>请选择</option>";
			data.systemCategoryUtil.levelOneId = 0;
		}
		$.each(data.systemCategoryUtil.levelOneList, function(i, item) {
			line += '<option value="' + item.pk + '">' + item.name
					+ '</option>';
		});
		$("#" + me.levelone).append(line);
		$("#" + me.levelone).val(data.systemCategoryUtil.levelOneId);
	},
	_refreshLevelTwo : function(data) {
		var me = this;
		$("#" + me.leveltwo).empty();
		$.each(data.systemCategoryUtil.levelTwoList, function(i, item) {
			var line = '<option value="' + item.pk + '">' + item.name
					+ '</option>';
			$("#" + me.leveltwo).append(line);
		});
		$("#" + me.leveltwo).val(data.systemCategoryUtil.levelTwoId);
	},
	_refreshLevelThree : function(data) {
		var me = this;
		$("#" + me.levelthree).empty();
		$.each(data.systemCategoryUtil.levelThreeList, function(i, item) {
			var line = '<option value="' + item.pk + '">' + item.name
					+ '</option>';
			$("#" + me.levelthree).append(line);
		});
		$("#" + me.levelthree).val(data.systemCategoryUtil.levelThreeId);
	}
}